//
// Created by ningjian on 18-6-7.
//

#ifndef RTPPULLER_RTPBUFFERREADER_HPP
#define RTPPULLER_RTPBUFFERREADER_HPP


#include <cstdint>
#include <cstring>
#include "StreamToMP4.hpp"

#define  BUFFER_MAX  1024 * 1024

class RTPBufferReader {
public:

    RTPBufferReader(long timespace = 60, std::string out_dir = ".");

    bool ReadBuffer(uint8_t * data,size_t len);

    ~RTPBufferReader();

private:
    long BCD2long(const unsigned char *data, int len);
    std::string bytes2HexString(unsigned char *data, int len);

private:

    long timespace;
    std::string out_dir;

    uint8_t socket_buffer[BUFFER_MAX];
    size_t socket_offset{0};
    uint8_t v_packet_buffer_data[BUFFER_MAX];
    size_t v_packet_buffer_offset{0};

    uint8_t a_packet_buffer_data[BUFFER_MAX];
    size_t a_packet_buffer_offset{0};

    StreamToMP4  *stream_to_mp4{NULL};
};


#endif //RTPPULLER_RTPBUFFERREADER_HPP
